package com.summerrain.colnect.plugins;

import java.util.ArrayList;

import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;

import android.util.Log;

import com.summerrain.colnect.jsouplib.GetAllCatgs;

public class allCollections extends Plugin {
	public static final String NATIVE_ACTION_STRING="nativeAction"; 
     

	@Override
	public PluginResult execute(String action, JSONArray data, String callbackId) {
		 Log.d("HelloPlugin", "Hello, this is a native function called from PhoneGap/Cordova!"); 
         if (NATIVE_ACTION_STRING.equals(action)) {
        	 ArrayList<String> resultSet = GetAllCatgs.getAllCategories();
        	 String finalStr = "";
        		finalStr +="<ul data-role=\"listview\">";
        	   	 for(int i=0; i< resultSet.size(); i++)
        	   	 {
        	   		 String tmp[] = resultSet.get(i).split("@");
        	   		String href = tmp[0].split("/")[tmp[0].split("/").length - 1];
        	   		 String img = tmp[1];
        	   		 String name = tmp[2];
        	   		 String desc = tmp[3];
        	   		 finalStr+="<li><a href='#' onclick='showCollectableOptions(\""+href+"\")'>";
        	   		 finalStr+="<img src=\""+img+"\" style='height:72px;'/>";
        	   		 finalStr+="<h3>"+name+"</h3><p>"+desc+"</p></a></li>";
        	   	 }
        	   	finalStr +="</ul>";
        	 
            return new PluginResult(PluginResult.Status.OK, finalStr); 
                
         } 
         return null; 
	}

}
